package com.ch.base.action;

import java.io.InputStream;

import org.apache.log4j.Logger;
import org.apache.struts2.ServletActionContext;

import com.ch.base.element.BaseAction;

public class FileSaveAsAction extends BaseAction {
	private final Logger log = Logger.getLogger(this.getClass());
	
	private String filePath; 	//檔案路徑
	private String fileName;	//檔案名稱
	private InputStream inputStream;
	
	public String execute() {
		try {
			inputStream = ServletActionContext.getServletContext().getResourceAsStream(this.filePath + "/" + this.fileName);
			//檔案不存在
			if(inputStream == null){
				errorMsg = "很抱歉，您所下載的檔案可能已被移除。";
				return "exception";
			}
		}catch (Exception e) {
			e.printStackTrace();
		}
		return SUCCESS;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public InputStream getInputStream() {
		return inputStream;
	}

	public void setInputStream(InputStream inputStream) {
		this.inputStream = inputStream;
	}

}
